export class PacketRuler
{
    private rulerIDs:{[key:string]:string;} = {};
    public SetNeedCompressPacket(packetID:number, packetMode:number):void{this.setRulerValue("C",packetID, packetMode)}
    public SetNeedDecompressPacket(packetID:number, packetMode:number):void{this.setRulerValue("D",packetID, packetMode)}
    public SetNeedGenDynamicKey(packetID:number, packetMode:number):void{this.setRulerValue("G",packetID, packetMode)}
    public SetPacketKey(key:string, packetID:number, packetMode:number):void{this.setRulerValue("K",packetID, packetMode,key)}
    private setRulerValue(flag:string,packetID:number, packetMode:number,value?:string):void
    {
        var key:string = this.GetPacketModeID(packetID, packetMode);
        this.rulerIDs[flag+"_"+key] = value?value:"OK";
    }
    private getRulerValue(flag:string,packetID:number, packetMode:number):string
    {
        var key:string = this.GetPacketModeID(packetID, packetMode);
        return this.rulerIDs[flag+"_"+key];
    }
    public ClearPacketKeys():void
    {
        for (let key in this.rulerIDs) 
        {
            if(key.charAt(0)=="K")
                delete this.rulerIDs[key];
        }
    }
    /**
    *Send:number = 0;
    *Receive:number = 1;
    **/			
    public IsNeetGenDynamicKey(packetID:number, packetMode:number):boolean{return this.getRulerValue("G",packetID,packetMode)!=null;}
    public GetPacketCKey(packetID:number, packetMode:number):string{return this.getRulerValue("K",packetID,packetMode);}	
    public IsNeedCompressPacket(packetID:number, packetMode:number):boolean{return this.getRulerValue("C",packetID,packetMode)!=null;}
    public IsNeedDecompressPacket(packetID:number, packetMode:number):boolean{return this.getRulerValue("D",packetID,packetMode)!=null;}
    protected GetPacketModeID(packetID:number, packetMode:number):string{return (packetMode == 0 ? "S_" : "R_") + packetID;}
    public Clear():void
    {   
        this.rulerIDs = {};
    }
    public dispose():void
    {
        this.rulerIDs = null;
    }
}
